import { BasicColumn, FormSchema } from '@apps/antd-admin/src/components/Table';
import { weChatList } from '@apps/ant-bus/src/views/business/platformManage/wechat/data/api';
import { render } from '@apps/antd-admin/src/hooks/render/renderUtils';
import { Api } from '../data/api';
export const columns: BasicColumn[] = [
  {
    title: '配置图标',
    dataIndex: 'configIcon',
    width: 60,
    customRender: render.renderImage,
  },
  {
    title: '配置名称',
    dataIndex: 'configName',
    width: 120,
  },
  {
    title: '应用公众号',
    dataIndex: 'weChatName',
    width: 120,
  },
  {
    title: '编码',
    dataIndex: 'configCode',
    width: 120,
  },
  {
    title: '排序',
    dataIndex: 'configSort',
    width: 120,
  },
  {
    title: '跳转方式',
    dataIndex: 'jumpType',
    width: 120,
    customRender: render.renderDict,
  },
  {
    title: '是否开启',
    dataIndex: 'isOpen',
    width: 80,
    renderApi: Api.setState,
    rowKey: 'configId',
    customRender: render.renderSwitch,
  },
  {
    title: '商品',
    dataIndex: 'goodsName',
    width: 120,
  },
  {
    title: '创建日期',
    dataIndex: 'createTime',
    width: 120,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'weChatId',
    label: '公众号',
    component: 'ApiSelect',
    colProps: { span: 5 },
    componentProps: {
      api: weChatList,
      params: {},
      labelField: 'weChatName',
      valueField: 'weChatId',
      immediate: true,
    },
  },
  {
    field: 'isOpen',
    label: '是否开启',
    component: 'Select',
    colProps: { span: 5 },
    componentProps: {
      options: [
        { label: '已开启', value: 1 },
        { label: '未开启', value: 2 },
      ],
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '配置名称',
    field: 'configName',
    component: 'Input',
    required: true,
  },
  {
    label: '公众号',
    field: 'weChatId',
    component: 'ApiSelect',
    required: true,
    componentProps: {
      api: weChatList,
      params: {},
      labelField: 'weChatName',
      valueField: 'weChatId',
      immediate: true,
    },
  },
  {
    label: '跳转方式',
    field: 'jumpType',
    required: true,
    component: 'ApiRadioGroup',
    componentProps: {
      dictCode: 'jumpType',
      stringToNumber: true,
    },
  },
  {
    label: '轮播图',
    field: 'configImg',
    component: 'ImageUpload',
    componentProps: {
      fileMax: 3,
    },
    ifShow: ({ values }) => {
      return values.jumpType == '3';
    },
  },
  {
    label: '外部链接',
    labelWidth: 100,
    field: 'content',
    component: 'InputTextArea',
    required: true,
    ifShow: ({ values }) => {
      return values.jumpType == '1';
    },
  },
  {
    label: '配置内容',
    field: 'content',
    component: 'TyEditor',
    ifShow: ({ values }) => {
      return values.jumpType == '2' || values.jumpType == '3';
    },
  },
  {
    label: '跳转路径',
    labelWidth: 100,
    field: 'pathUrl',
    component: 'Input',
    required: true,
    ifShow: ({ values }) => {
      return values.jumpType == '3';
    },
  },
  {
    label: 'JS脚本',
    field: 'content',
    component: 'InputTextArea',
    ifShow: ({ values }) => {
      return values.jumpType == '4';
    },
  },
  {
    label: '商品',
    field: 'goodsId',
    component: 'ApiModalSelect',
    required: false,
    show: ({ values }) => {
      return values.jumpType == '3';
    },
    componentProps: {
      multiple: '',
      selectConfig: {
        api: '/goods/page',
        rowKey: 'goodsId',
        labelKey: 'goodsName',
        modalTitle: '商品选择',
        searchForm: [
          {
            label: '商品名称',
            field: 'goodsName',
            component: 'Input',
          },
        ],
        columns: [
          {
            title: '商品封面',
            dataIndex: 'coverImg',
            width: 120,
            customRender: render.renderImage,
          },
          {
            title: '商品名称',
            dataIndex: 'goodsName',
            width: 80,
          },
        ],
      },
    },
  },
  {
    label: '排序号',
    field: 'configSort',
    component: 'InputNumber',
    required: true,
  },
  {
    label: '配置code',
    field: 'configCode',
    component: 'Input',
  },
  {
    label: '配置图标',
    field: 'configIcon',
    component: 'ImageUpload',
    required: true,
  },
  {
    label: '备注',
    field: 'remark',
    component: 'Input',
  },
];
